package com.zhny.aiot.gdsfj.plugin.model;

import com.zhny.aiot.plugin.core.utils.MessageUtils;
import com.zhny.aiot.plugin.modbus.device.ModemConfig;
import com.zhny.aiot.plugin.modbus.device.ModemDevice;
import com.zhny.aiot.plugin.modbus.handler.model.ModemResponseMessage;
import com.zhny.aiot.plugin.model.MessageEntry;
import com.zhny.aiot.plugin.model.MessageType;

public abstract class FertilizerResultModel {
    private final ModemResponseMessage modemBusResponse;
    private final ModemDevice device;

    public FertilizerResultModel(ModemResponseMessage modemBusResponse, ModemDevice device){

        this.modemBusResponse = modemBusResponse;
        this.device = device;
    }

    public ModemResponseMessage getModemBusResponse() {
        return modemBusResponse;
    }

    public ModemDevice getDevice() {
        return device;
    }

    public void onHandler(){
        MessageEntry entry = MessageUtils.createMessageEntry (this.device.getId ());
        entry.setType (MessageType.RESULT);
        entry.getProperties().put("gprs",((ModemConfig)device.getConfig()).getGprsNo());
        entry.getProperties().put("address",((ModemConfig)device.getConfig()).getAddress());
        onDecoder(entry);
    }

    protected abstract void onDecoder(MessageEntry entry);

}
